import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { User } from './user.entity';
import { Goods } from 'src/module/grocery/entities/goods.entity';

@Entity('product_fav', { schema: 'shop' })
export class FavEntity {
  constructor(partial: Partial<FavEntity>) {
    Object.assign(this, partial);
  }

  @PrimaryGeneratedColumn()
  id: number;

  // @Column('tinyint', { name: 'user_id', comment: '用户id' })
  @ManyToOne(() => User) // 装饰器用于定义多对一的关系
  @JoinColumn({ name: 'user_id' }) // 装饰器用于指定外键列的名称
  user: User;

  // @Column('tinyint', { name: 'product_id', comment: '商品id' })
  @ManyToOne(() => Goods)
  @JoinColumn({ name: 'product_id' })
  product: Goods;

  @CreateDateColumn({ name: 'create_time', comment: '收藏操作时间' })
  createTime: Date;
}
